package com.njbw.user.designPattern.filterPattern;

import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 定义过滤器的执行顺序
 */
public class ArticleFilterFactory {

    public static List<IArticleFilter> createArticleFilter(List<ArticleFilterEnum> articleFilterEnumList) {
        List<IArticleFilter> articleFilterList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(articleFilterEnumList)) {
            articleFilterList = articleFilterEnumList.stream().map(ArticleFilterFactory::createFilter).collect(Collectors.toList());
        }
        return articleFilterList;
    }

    /**
     * 根据枚举值找到对应的 Filter
     */
    public static IArticleFilter createFilter(ArticleFilterEnum articleFilterEnum) {
        IArticleFilter articleFilter = null;
        switch (articleFilterEnum) {
            case WORD_COUNT:
                articleFilter = new WordCountArticleFilter();
                break;
            default:
                break;
        }
        return articleFilter;
    }
}
